package com.xigua.nio;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOFileChannel03 {
    public static void main(String[] args) throws IOException {

        FileInputStream fileInputStream = new FileInputStream("d:/1.txt");
        FileOutputStream fileOutputStream = new FileOutputStream("d:/2.txt");

        FileChannel inChannel = fileInputStream.getChannel();
        FileChannel outChannel = fileOutputStream.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate(5);

        while (true){
            byteBuffer.clear();
            int read = inChannel.read(byteBuffer);
            System.out.println("read="+read);
            if (read == -1){
                break;
            }
            byteBuffer.flip();
            outChannel.write(byteBuffer);
        }
        fileInputStream.close();
        fileOutputStream.close();

    }
}
